<!--文件归档-->
<template>
<div>
  <div class="top-title">文件归档</div>
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <el-row>
      <el-col :span="6">
        <el-form-item label="经办人：" prop="responsiblePerson">
          <el-input v-model="ruleForm.responsiblePerson"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="经办日期：" prop="date">
          <el-input v-model="ruleForm.date"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="经办部门：" prop="depart">
          <el-input v-model="ruleForm.depart"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="№：" prop="number">
          <el-input v-model="ruleForm.number"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <el-form-item label="经办单位：" prop="unit">
          <el-input v-model="ruleForm.unit"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <div class="tab-part">
      <span class="part-line"></span>
      <span class="part-title">基本信息</span>
    </div>
    <el-row>
      <el-col :span="12">
        <el-form-item label="项目名称：" prop="entryName">
          <el-input v-model="ruleForm.entryName"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="项目编号：" prop="entryNumber">
          <el-input v-model="ruleForm.entryNumber"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="项目负责人：" prop="responsiblePerson">
          <el-input v-model="ruleForm.responsiblePerson"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="6">
        <el-form-item label="归档人：" prop="archived">
          <el-input v-model="ruleForm.archived"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="归档日期：" prop="date">
          <el-input v-model="ruleForm.date"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="存档位置：" prop="archiveLocation">
          <el-input v-model="ruleForm.archiveLocation"></el-input>
        </el-form-item>
      </el-col>
    </el-row>
    <div class="tab-part">
      <span class="part-line"></span>
      <span class="part-title">项目文件</span>
    </div>
    <div class="operate-button" v-if="ModalType=='add'">
      <el-button @click="add" icon="el-icon-plus">新建</el-button>
      <el-button @click="" icon="el-icon-document-copy">复制</el-button>
      <el-button icon="el-icon-delete" @click="del">删除</el-button>
    </div>
    <el-table :data="tableData" border @selection-change="handleSelectionChange" style="width: 100%;margin-bottom: 10px">
      <el-table-column
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column prop="id" label="序号"></el-table-column>
      <el-table-column prop="fileName" label="文件名称">
        <template slot-scope="scope">
          <el-input v-model="scope.row.fileName"></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="fileNo" label="文件编号">
        <template slot-scope="scope">
          <el-input v-model="scope.row.fileNo"></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="date" label="出具日期">
        <template slot-scope="scope">
          <el-input v-model="scope.row.date"></el-input>
        </template>
      </el-table-column>
      <el-table-column prop="file" label="文件附件">
        <template slot-scope="scope">
          <el-input v-model="scope.row.file"></el-input>
        </template>
      </el-table-column>
    </el-table>
    <div v-if="ModalType=='add'" style="display: flex;justify-content: flex-end;margin-top: 16px">
      <el-button @click="send('ruleForm')">发送</el-button>
      <el-button type="primary" @click="save('ruleForm')">保存待发</el-button>
    </div>
  </el-form>
</div>
</template>

<script>
export default {
  name: 'documentFiling',
  data(){
    return{
      ruleForm: {
        responsiblePerson: '',
        date: '',
        depart: '',
        number: '',
        unit: '',
        entryName: '',
        planStartTime: '',
        planEndTime: '',
        duration: '',
        entryNumber: '',
        expectedResults: '',
        achieveResults: '',
        summary: '',
        approval: ''
      },
      rules: {
        // responsiblePerson: [
        //   { required: true, message: '请输入合同名称', trigger: 'blur' },
        //   { max: 20, message: '长度最大20个字符', trigger: 'blur' }
        // ],
        // date: [
        //   { required: true, message: '请输入合同编号', trigger: 'blur' }
        // ]
      },
      tableData: [
        {
          id:'1',
          responsiblePerson:'',
          depart:''
        }
      ],
      multipleSelection: []
    }
  },
  props: {
    row: {
      type: Object,
      default: () => {
      }
    },
    //关闭弹窗
    closeModal: {
      type: Function,
      default: null
    },
    ModalType: {
      type: String,
      default: ''
    }
  },
  watch: {
    row(n) {
      if (Object.keys(n).length !== 0) {
        this.ruleForm = Object.assign({}, n)
      }
    }
  },
  mounted() {
    if (Object.keys(this.row).length !== 0) {
      this.ruleForm = Object.assign({}, this.row)
    }
  },
  methods: {
    //发送
    send(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$message.success('发送成功！')
          this.closeModal()
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    //保存
    save(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$message.success('保存成功！')
          this.closeModal()
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },

    //勾选
    handleSelectionChange(val) {
      this.multipleSelection = val;
      console.log(11111111,val)
    },

    //新增
    add(){
      //id自增
      this.tableData.forEach((e,index)=>{
        e.id=index+1
      })
      let index = this.tableData.length
      this.tableData.push({
        id:index+1,
        responsiblePerson:'',
      })
    },

    //删除
    del(){
      if(this.multipleSelection.length!==1){
        this.$message.warning('请选择一条要删除的数据！')
      }else {
        let index = this.multipleSelection[0].id;
        this.tableData.splice(index-1, 1);
        this.tableData.forEach((e,index)=>{
          e.id=index+1
        })
      }
    },
  }
}
</script>

<style scoped lang="scss">
.top-title {
  font-size: 24px;
  font-weight: bold;
  color: #ffffff;
  background: #1ab394;
  padding: 16px;
  align-items: center;
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

.tab-part {
  display: flex;
  align-items: center;
  border-bottom: 2px solid #e7eff3;
  padding-bottom: 10px;
  margin-bottom: 16px;

  .part-line {
    display: inline-block;
    width: 4px;
    height: 16px;
    background-color: #1ab394;
    float: left;
    margin-top: 2px;
    margin-right: 10px;
  }

  .part-title {
    font-weight: bold;
  }
}
.el-button--mini.is-round {
  padding: 6px 4px !important;
}
.page-img{
  width: 100%;
}
.operate-button{
  margin-bottom: 10px;
  float: right;
}
</style>
